<div class="index">
<?php if($isAjax==0){?>
<style>
	.ui-autocomplete-loading { background: white url('../img/loading.gif') right center no-repeat; }
</style>
<h2>Vui lòng nhập thông tin tìm kiếm</h2>
<?php
	echo $this->Html->css(array('jquery.ui.position','jquery.ui.autocomplete'));
	echo $this->Html->script(array('jquery.ui.position','jquery.ui.autocomplete')); 
?>
<script type="text/javascript">
<!--

$(function() {
	$("#tensach").autocomplete({
		 source: $('#linkdausach').val(),
		 minLength: 1,
		 change: function(event, ui)
		 {
			 $.ajax({
			 async:true,
			  data:$("#tensach").closest("form").serialize(), 
			  dataType:"html", 
			  success:function (data, textStatus){
				  $("#ketqua").html(data);},
				   type:"post",
				   url:$('#timkiem').val()
					   });
		   }
		});
	$("#nxb").autocomplete({
		 source: $('#linknxb').val(),
		 minLength: 1
		});
	$("#lv").autocomplete({
		 source: $('#linklv').val(),
		 minLength: 1
		});
	$("#nn").autocomplete({
		 source: $('#linknn').val(),
		 minLength: 1
		});
	
});

//-->
</script>
<?php echo $form->hidden('',array('id'=>'timkiem','value'=>$this->webroot.'dausaches/timkiem'));?>
<?php echo $form->hidden('',array('id'=>'linkdausach','value'=>$this->webroot.'dausaches/autocompletetensach'));?>
<?php echo $form->hidden('',array('id'=>'linknxb','value'=>$this->webroot.'dausaches/autocompletenxb'));?>
<?php echo $form->hidden('',array('id'=>'linklv','value'=>$this->webroot.'dausaches/autocompletelv'));?>
<?php echo $form->hidden('',array('id'=>'linknn','value'=>$this->webroot.'dausaches/autocompletenn'));?>
<?php echo $form->create("Dausach",array());?>
<table id='timkiem'>
<tr>
<td><?php echo $form->input('tensach',array('id'=>'tensach','label'=>'Tên sách','type'=>'text')); ?></td>
<td><?php echo $form->input('checkten',array('id'=>'checkten','label'=>'OR','type'=>'checkbox'));?></td>
</tr>
<tr>
<td><?php echo $form->input("tacgia",array('id'=>'tentg','label'=>'Tác giả','type'=>'text'));?></td>
<td><?php echo $form->input('checktg',array('id'=>'checktg','label'=>'OR','type'=>'checkbox'));?></td>
</tr>
<tr>
<td><?php echo $form->input("nxb",array('id'=>'nxb','label'=>'Nhà xuất bản','type'=>'text'));?></td>
<td><?php echo $form->input('checknxb',array('id'=>'checknxb','label'=>'OR','type'=>'checkbox'));?></td>
</tr>
<tr>
<td><?php echo $form->input("linhvuc",array('id'=>'lv','label'=>'Lĩnh vực','type'=>'text'));?></td>
<td><?php echo $form->input('checklv',array('id'=>'checklv','label'=>'OR','type'=>'checkbox'));?></td>
</tr>
<tr>
<td><?php echo $form->input("ngonngu",array('id'=>'nn','label'=>'Ngôn ngữ','type'=>'text'));?></td>
<td><?php echo $form->input('checknn',array('id'=>'checknn','label'=>'OR','type'=>'checkbox'));?></td>
</tr>
<tr>
<td>
<?php echo $form->input('sort',array('id'=>'sort','label'=>'Sắp xếp theo','type'=>'select','options'=>array('tensach'=>'Tên sách','tacgia'=>'Tác giả','namxb'=>'Năm xuất bản')));//,'sachmoi'=>'Sách mới','sachcu'=>'Sách cũ'?>
<?php echo $form->input('thutu',array('id'=>'thutu','label'=>'Thứ tự','type'=>'select','options'=>array('ASC'=>'Tăng dần','DESC'=>'Giảm dần')));?>
</td>
<td><?php echo $js->submit('Tìm',array('url'=>array('controller'=>'dausaches','action'=>'timkiem'),'update'=>'#ketqua'));?></td>
</tr>
</table>
<div id='ketqua'>
<h2>Kết quả tìm kiếm</h2>
<?php if(!empty($dausaches)){?>
<table id='tables'>
<tr>
<th>Tên sách</th>
<th>Tác giả</th>
<th>Năm xuất bản</th>
<th>NXB</th>
<th>Lĩnh vực</th>
<th>Ngôn ngữ</th>
</tr>
<?php foreach ($dausaches as $dausach):?>
<tr>
<td><?php echo $html->link($dausach['Dausach']['tensach'],array('controller'=>'cuonsaches','action'=>'dscuonsach',$dausach['Dausach']['id'])) ?></td>
<td><?php echo $dausach['Dausach']['tacgia'] ?></td>
<td><?php echo date('Y',strtotime($dausach['Dausach']['namxb'])); ?></td>
<td><?php echo $dausach['Nhaxuatban']['tennxb'] ?></td>
<td><?php echo $dausach['Linhvuc']['tenlv'] ?></td>
<td><?php echo $dausach['Ngonnguk']['tennn'] ?></td>
</tr>
<?php endforeach;?>
</table>
<p>
	<?php
	echo $this->Paginator->counter(array(
	'format' => __('Trang %page%/%pages%, hiện có %count% mẫu tin', true)
	));
	?>	</p>

	<div class="paging">
		<?php echo $this->Paginator->prev('<< ' . __('trở về', true), array(), null, array('class'=>'disabled'));?>
	 | 	<?php echo $this->Paginator->numbers();?>
 |
		<?php echo $this->Paginator->next(__('tiếp', true) . ' >>', array(), null, array('class' => 'disabled'));?>
	</div>
<?php }?>
</div>
<?php $this->Js->get('#tensach')->event('keyup',
							$this->Js->request(array('controller' => 'dausaches', 'action' => 'timkiem'),
							array('update' => '#ketqua','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));?>

<?php }else{?>
<?php if(!empty($dausaches)){?>
<table id='tables'>
<tr>
<th>Tên sách</th>
<th>Tác giả</th>
<th>Năm xuất bản</th>
<th>NXB</th>
<th>Lĩnh vực</th>
<th>Ngôn ngữ</th>

</tr>
<?php foreach ($dausaches as $dausach):?>
<tr>
<td><?php echo $html->link($dausach['Dausach']['tensach'],array('controller'=>'cuonsaches','action'=>'dscuonsach',$dausach['Dausach']['id'])) ?></td>
<td><?php echo $dausach['Dausach']['tacgia'] ?></td>
<td><?php echo date('Y',strtotime($dausach['Dausach']['namxb'])); ?></td>
<td><?php echo $dausach['Nhaxuatban']['tennxb'] ?></td>
<td><?php echo $dausach['Linhvuc']['tenlv'] ?></td>
<td><?php echo $dausach['Ngonnguk']['tennn'] ?></td>

</tr>
<?php endforeach;?>
</table>
<p>
	<?php
	echo $this->Paginator->counter(array(
	'format' => __('Trang %page%/%pages%, hiện có %count% mẫu tin', true)
	));
	?>	</p>

	<div class="paging">
		<?php echo $this->Paginator->prev('<< ' . __('Trước', true), array(), null, array('class'=>'disabled'));?>
	 | 	<?php echo $this->Paginator->numbers();?>
 |
		<?php echo $this->Paginator->next(__('Sau', true) . ' >>', array(), null, array('class' => 'disabled'));?>
	</div>
<?php }else{?>
<h2>Không tìm thấy</h2>
<?php }}?>
</div>